<?php
/************************************************************
*                                                           *
*       author: Sebastian Elias Franco Brantes              *
*       description: Controlador de Usuarios                *
*       Date: 29-05-2013                                    *
*                                                           *
************************************************************/

class UsuariosController extends ControllerBase 
{

    private $_usuarioModel;
    public function __construct(){
        parent::__construct(); 
        require_once './Protected/Models/usuariosModel.php';
        $this->_usuarioModel = new UsuarioModel();      
    } 
    
    public function validarUsuario(){ 
        try{
            if (isset($_POST['usuUsername'])){
                $item = $this->_usuarioModel->consultarUsuario($_POST['usuUsername'], $_POST['usuPassword']);
                $resultado = $item->fetchObject();
                if ($resultado->usu_usuario != ""){
                    $_SESSION['CPANELSF'] = $_POST['usuUsername'];
                    $_SESSION['CPANELSF_menu'] = 'home';
                    echo "success";
                }
                else{
                    echo '';
                }
            }
        }catch (Exception $e){
            echo 'Excepción capturada: '.  $e->getMessage();
        }
    }
    
    public function cerrarSesion(){ 
        session_destroy();
        echo '<meta content="0;URL=./" http-equiv="REFRESH"> </meta>';
    }  
    
    public function index(){   
        $this->view->show("usuarios.php","");
    }
    
}
?>
